/**
 * ClassName deptController.js
 * 部门管理控制器
 */
Ext.define("AM.controller.deptController", {
	extend : "Ext.app.Controller",
	GridActionUtil: Ext.create("AM.util.GridActionUtil"),
	init : function() {
		this.getGridObj = function(button) {
			return button.ownerCt.ownerCt;
		};
		this.getTreeObj = function(button) {
			return button.ownerCt.ownerCt.ownerCt.ownerCt.child(
							"#west-tree").child("#deptTree");
		};
		this.control( {
			//工具条的添加按钮事件
			"deptlist button[id=delete]" : {
				click : function(ab) {
					var grid = this.getGridObj(ab);
					var tree = this.getTreeObj(ab);
					//alert(grid);
					this.GridActionUtil.doDelete(grid, tree);
				}
			},
			"deptlist button[id=save]" : {
				click : function(ab) {
					var grid = this.getGridObj(ab);
					var tree = this.getTreeObj(ab);
					//alert("save");
					this.GridActionUtil.doSave(grid, tree);
				}
			},
			"deptlist button[id=add]" : {
				click : function(ab) {
					//得到表格对象	
					var grid = this.getGridObj(ab);
					var modelObj = {
						text : '',
						id : '',
						info : '',
						orderIndex : 0,
						manager : '',
						nodeType : 'root',
						leaf : true
					};

					var tree = this.getTreeObj(ab);
					//alert(tree.getHeight());
					this.GridActionUtil.doInsert(grid,
							modelObj, tree);
				}
			}
		})
	},
	views : [ 'deptTree', 'deptList', 'MainLayout' ], //'deptList', 
	stores : [ 'deptStore4Tree', 'deptStore' ], //deptStore
	models : [ 'deptModel' ]
//models: ['deptModel']
		});